// 检查是否有用户基本信息授权
function checkAllowUserInfo(){
  var nickName = wx.getStorageSync("nickName");
  console.log(nickName);
  if(nickName){
    return true;
  }else{
    console.log(1111111);
    return false;
  }
}

// 检查是否授权手机号
function checkAllowPhoneNumber(){

}

/**
     * 测试判断用户方法
     */
    var checkUser = (options) => {
      var encarr = [{
        fidEnc: fidEnc
      }]
      var enc = app.generateEnc(encarr)
      return new Promise((resolve, reject) => {
        wx.request({
          url: 'https://manageshequ3.chaoxing.com/api/checkfidenc?fidEnc=' + options.fidEnc+ '&enc=' + enc,
          method: 'POST',
          header: {
            'content-type': 'application/x-www-form-urlencoded' // 默认值
          },
          success: function (res) {
            console.log(res);
            if (res.data.code == 200) {
              console.log(res.data.data)
              let site = res.data.data;
              try {
                JSON.parse(site.custom)
              } catch (error) {
                site.custom = site.custom != '' ? app.decrypt(site.custom) : site.custom
                site.appid = site.appid!=''?app.decrypt(site.appid):site.appid
                site.fidEnc = site.fidEnc!=''?app.decrypt(site.fidEnc):site.fidEnc
                site.fidEncH5 = site.fidEncH5!=''?app.decrypt(site.fidEncH5):site.fidEncH5
                site.secret = site.secret!=''?app.decrypt(site.secret):site.secret
              }
              app.globalData.passEnc = true;
              app.globalData.fid = site.fid;
              app.globalData.site = site;
              // wx.setStorageSync("fid", site.fid);
              //2020-03-24 需要判断下缓存中单位与pages/index/index?fid=xxxxx这个单位是否为同一个，不同的话，切换fid,并清空登录信息
              var cxid = wx.getStorageSync('cxid');
              var fid = wx.getStorageSync('fid');
             if (cxid && cxid > 0 && fid && fid > 0){
                if(fid != app.globalData.fid){
                  wx.setStorageSync('fid', app.globalData.fid);//切换fid
                  wx.removeStorageSync('cxid');//清空cxid
                  wx.removeStorageSync('userInfo');//清空userinfo
                  console.log("清空用户信息");
                  wx.setStorageSync('site', site);//更新site
                  wx.removeStorageSync('openid');//清空openid
                  wx.removeStorageSync('phone');//清空phone
                  // wx.removeStorageSync('openid4');//清空openid4
                  wx.removeStorageSync('session_key');//清空sessionkey
                  wx.setStorageSync('hasLogin', false);//切换登录状态
                  wx.setStorageSync('permission', false);//切换登录状态
                }
              }else{
               wx.setStorageSync("fid", site.fid);
               wx.setStorageSync('site', site);//更新site
              }
            } else {
              console.log("enc校验未通过")
            }
            console.log("测试用户校验失败");
          },
          fail: function () {
            console.log("校验服务器出错")
          }
        })
    })
  }

module.exports = {
  checkAllowUserInfo: checkAllowUserInfo,
  checkUser: checkUser
}